package org.liaohailong.library.event;


import androidx.annotation.NonNull;

import java.lang.reflect.Method;

/**
 * create by liaohailong
 * time 2022/9/22 16:32
 * desc: 消息订阅 反射信息类
 */
public class MessageReflectInfo {
    @NonNull
    private final Object owner;
    @NonNull
    private final Method method;
    @NonNull
    private final Class<?> eventClz;

    public MessageReflectInfo(@NonNull Object owner,
                              @NonNull Method method,
                              @NonNull Class<?> eventClz) {
        this.owner = owner;
        this.method = method;
        this.eventClz = eventClz;
    }

    @NonNull
    public Object getOwner() {
        return owner;
    }

    @NonNull
    public Method getMethod() {
        return method;
    }

    @NonNull
    public Class<?> getEventClz() {
        return eventClz;
    }

    public void onEvent(@NonNull Object event) {
        try {
            method.invoke(owner, event);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
